<!-- 侧边栏sop状态 -->
<template>
  <div class="sopState">
    <div class="sopTitle">
      <div @click="sopState = 1" :class=" sopState == 1 ? 'sopTitleText active' : 'sopTitleText' ">快速回复</div>
      <div @click="sopState = 2" :class=" sopState == 2 ? 'sopTitleText active' : 'sopTitleText' ">自动SOP执行进度</div>
    </div>
    <div class="sopContent">
      <div v-if="sopState == 1" class="replyClass">
        <div v-for="item in scriptList" :key="item.id" class="scriptItem">
          <div class="titleClass" @click="scriptClick(item)">
            <div class="title">{{ item.title }}</div>
            <div :class="personalIndex == item.id ? 'rotateTrue rotateFalse' : 'rotateTrue' ">
              <el-icon><ArrowRight /></el-icon>
            </div>
          </div>
          <div class="childrenClass" v-if="personalIndex == item.id">
            <div v-for="child in item.children" :key="child.id" :class="child.state ? 'childrenItem active' : 'childrenItem' " @click="childrenReplyClick(child)">
              {{ child.text }} 
            </div>
          </div>
        </div>
      </div>
      <div v-if="sopState == 2" class="speedClass">
        <div v-for="item in implementList" :key="item.id" class="scriptItem">
          <div class="titleClass" @click="implementClick(item)">
            <div class="title">{{ item.title }}</div>
            <div :class="implementIndex == item.id ? 'rotateTrue rotateFalse' : 'rotateTrue' ">
              <el-icon><ArrowRight /></el-icon>
            </div>
          </div>
          <div class="childrenClass" v-if="implementIndex == item.id">
            <div v-for="child in item.children" :key="child.id" @click="childrenImplementClick(child)">
              <div :class="child.state ? 'childrenItem active' : 'childrenItem' ">{{ child.text }}</div>
              <div class="implementClass">
                <div>{{ child.implementState ? '已执行' : '等待执行' }}</div>
                <div>{{ child.date }}</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="sopBottom" v-show="selectScriptList.length > 0">
      <div class="text">选中 {{ selectScriptList.length }} 条话术</div>
      <div>
        <el-button type="info" @click="sendClick">发送</el-button>
      </div>
    </div>
  </div>
</template>


<script setup>
import { computed,ref,onMounted } from 'vue';
//import { } from "@/api/api.js"

let sopState = ref(true);

//#region
let selectScriptList = ref([]);//选中的话术
let personalIndex = ref(null);
let scriptList = ref([
  {
    title: "用途话术1",
    id: 1,
    children: [],
  },
  {
    title: "用途话术2",
    id: 2,
    children: [],
  }
])
const scriptClick = (item) => {//打开话术列表
  if(personalIndex.value == null){
    personalIndex.value = item.id;
  } else {
    personalIndex.value = personalIndex.value == item.id ? null : item.id;
  }

  if(personalIndex.value){
    if(item.children.length == 0){
      item.children = [
        {
          text:"你必须知道的8种产品设计能力提升技巧1",
          id: 11,
          state: false,
        },
        {
          text:"你必须知道的8种产品设计能力提升技巧2",
          id: 12,
          state: false,
        }
      ]
    }
  }
}
const childrenReplyClick = (item) => {//选择话术
  item.state = !item.state;
  if(item.state){
    selectScriptList.value.push(item)
  } else {
    let i = selectScriptList.value.findIndex(ele => {
      return ele.id == item.id
    })
    if(i != -1){
      selectScriptList.value.splice(i,1)
    }
  }
}
const sendClick = () => {
  console.log(selectScriptList.value);
  scriptList.value.forEach(element => {
    element.children.forEach(ele => {
      ele.state = false
    })
  })
  selectScriptList.value = []
}
//#endregion

//#region
let selectImplementList = ref([]);
let implementIndex = ref(null);
let implementList = ref([
  {
    title: "新客户SOP",
    id: 1,
    children: [],
  },
  {
    title: "购买客户SOP",
    id: 2,
    children: [],
  }
])
const implementClick = (item) => {//打开sop列表
  if(implementIndex.value == null){
    implementIndex.value = item.id;
  } else {
    implementIndex.value = implementIndex.value == item.id ? null : item.id;
  }

  if(implementIndex.value){
    if(item.children.length == 0){
      item.children = [
        {
          text:"当你在工作或者学习的时候",
          id: 11,
          state: false,
          implementState: true,
          date: "2023年07月14日"
        },
        {
          text:"突然窜出一个朋友拉你聊一些有的没的",
          id: 12,
          state: false,
          implementState: false,
          date: "2023年07月14日"
        }
      ]
    }
  }
}
const childrenImplementClick = (item) => {//选择sop
  item.state = !item.state;
  if(item.state){
    selectImplementList.value.push(item)
  } else {
    let i = selectImplementList.value.findIndex(ele => {
      return ele.id == item.id
    })
    if(i != -1){
      selectImplementList.value.splice(i,1)
    }
  }
}
//#endregion
</script>


<style lang="scss" scoped>
.sopState{
  width: 100%;
  height: 100%;
  background-color: #fff;
  .sopTitle{
    width: 100%;
    display: flex;
    .sopTitleText{
      width: 50%;
      font-weight: 400;
      font-size: 16px;
      color: rgb(16, 16, 16);
      cursor: pointer;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 65px;
    }
    .active{
      color: #fff;
      background: rgb(165, 211, 255);
    }
  }
  .sopContent{
    height: calc( 100% - 117px);
    padding: 20px 10px;
    overflow-y: auto;
    .replyClass,.speedClass{
      .scriptItem{
        .titleClass{
          display: flex;
          justify-content: space-between;
          border-radius: 4px;
          padding: 10px 10px;
          margin-top: 10px;
          cursor: pointer;
          background-color: #f1f3ff;;
          .title{
            font-weight: 400;
            font-size: 14px;
            color: rgb(16, 16, 16);
          }
          .rotateTrue{
            transition:  0.5s;
            transform: rotate(0);
          }
          .rotateFalse{
            transform: rotate(90deg);
          }
        }
        .childrenClass {
          .childrenItem{
            &:hover{
              background-color: rgb(241, 243, 255);
            }
            border-radius: 4px;
            padding: 10px 10px;
            margin-top: 10px;
            cursor: pointer;
            background-color: rgb(249, 249, 249);
            font-weight: 400;
            font-size: 14px;
            color: rgb(16, 16, 16);
          }
          .active{
            background-color: rgb(241, 243, 255);
          }
          .implementClass{
            display: flex;
            justify-content: space-between;
            font-size: 12px;
            color: #bbb;
            padding: 3px 5px 0;
          }
        }
      }
    }
  }
  .sopBottom{
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 10px;
    .text{
      font-weight: 400;
      font-size: 14px;
      color: rgb(16, 16, 16);
    }
  }
}
</style>